function orderChange(){
	if($("#order_status").val()==''){
		alert(order_changeStatusMsg);return false;
	}
	$("#order_change_form").submit();
}
function unsetSesssionDiv(sessionAuth,incrValue,logAuth){
	if(sessionAuth=='paper'){
		var unsetDiv=sessionAuth;
	}else if(sessionAuth=='magazine'){
		var unsetDiv=sessionAuth;
	}else if(sessionAuth=='home'){
		var unsetDiv=sessionAuth;	
	}
	if(logAuth=='users'){
		var url=BASE_URL+'users/unset-session-div';
	}else if(logAuth=='admin'){
		var url=ADMIN_BASE_URL+'admin/unset-session-div';
	}
	$.ajax({
		type:'POST',
		url:  url,
		data:{session_div:unsetDiv,incr_value:incrValue},
		success: function(data){
			if(data.output=='success'){
				if(logAuth=='users'){
					var returnUrl=BASE_URL+'users/confirm-order';
				}else if(logAuth=='admin'){
					var returnUrl=ADMIN_BASE_URL+'admin/confirm-order';
				}
				window.location=returnUrl;
			}
		}
	});
}
function checkDimensions(adType,logAuth){
	var flag=true;
	if(adType=='magzine'){
		var val = $('#magizenupload').val();
	}else if(adType=='paper'){
		var val = $('#paperupload').val();
	}else if(adType=='home_delivery'){
		var val = $('#homeupload').val();
	}	
	if(val!=""){
		switch(val.substring(val.lastIndexOf('.') + 1).toLowerCase()){
			case 'gif': case 'jpg': case 'png': case 'jpeg':
				flag=true;
				break;
			default:
				$(this).val('');
				alert(ad_postingImageFormatMsg);
				flag=false;
				break;
		}
	}
	if(flag==true){
		if(adType=='magzine'){
			var file_path = $('#magizenupload')[0].files[0];
		} else if(adType=='paper'){
			var file_path = $('#paperupload')[0].files[0];
		} else if(adType=='home_delivery'){
			var file_path = $('#homeupload')[0].files[0];
		}
			
		if(file_path.size > 1000141){
			alert(ad_postingImageSizeLengthlessthanMbMsg);
			return false;
		} else if(file_path.size > 1000141){
			alert(ad_postingImageSizeLengthlessthanMbMsg);
			return false;
		} else if(file_path.size > 1000141){
			alert(ad_postingImageSizeLengthlessthanMbMsg);
			return false;
		}
		else
		{	
			if(logAuth=='admin'){
				var url=ADMIN_BASE_URL+'users/check-dimensions';
			}else if(logAuth=='users'){
				var url=BASE_URL+'users/check-dimensions';
			}
			var formData = new FormData();
			formData.append('file', file_path);
			$.ajax({
				url : BASE_URL+'users/check-dimensions',
				type : 'POST',
				data : formData,
				processData : false,
				processData: false,  // tell jQuery not to process the data
				contentType: false,  // tell jQuery not to set contentType
				success : function(data) {
					if(data.success=='success'){					
						if(adType=='magzine'){
							$("#checkImage_magzine").val(1);
							$("#price_dimension_magiz").val(data.price_dimension);
							$("#magazineImage").html(data.price_dimension+' Rs');							
						} else if(adType=='paper'){
							$("#checkImage_paper").val(1);
							$("#price_dimension_paper").val(data.price_dimension);
							$("#paperImage").html(data.price_dimension+' Rs');
						} else if(adType=='home_delivery'){
							$("#checkImage_home").val(1);
							$("#price_dimension_home").val(data.price_dimension);
							$("#homeImage").html(data.price_dimension+' Rs');
						}
					}else if(data.success=='not success'){
						if(adType=='magzine'){
							$("#checkImage_magazine").val(0);
						} else if(adType=='paper'){
							$("#checkImage_paper").val(0);
						} else if(adType=='home_delivery'){
							$("#checkImage_home").val(0);
						}
						alert(ad_postingImageDimensionsNotProperMsg);return false;
					}
				}
			});
		}
	}
}
function lengthLetter(adType,event,logAuth){
	if(adType=='print_paper'){
		var textOnLetters=$("#textAreaPaper").val();
		if (event.keyCode != 9) {
			$('#lengthPaper').html(textOnLetters.length+1);
			$('#length_paper').val(textOnLetters.length+1);
		}
	}else if(adType=='ad_magazine'){
		var textOnLetters=$("#textAreaMagazine").val();
		if (event.keyCode != 9) {
			$('#lengthMagazine').html(textOnLetters.length+1);
			$('#length_magazine').val(textOnLetters.length+1);
		}
	}else if(adType=='ad_homedelivery'){
		var textOnLetters=$("#textAreaHome").val();
		if (event.keyCode != 9) {
			$('#lengthHomedelivery').html(textOnLetters.length+1);
			$('#length_home_delivery').val(textOnLetters.length+1);
		}
	}
}
function getPriceLetters(adType,logAuth){
	if(adType=='print_paper'){
		var textOnLetters=$("#textAreaPaper").val();
	}else if(adType=='ad_magazine'){
		var textOnLetters=$("#textAreaMagazine").val();
	}else if(adType=='ad_homedelivery'){
		var textOnLetters=$("#textAreaHome").val();
	}
	if(textOnLetters!=''){
		var lenLetteres=textOnLetters.length;
		if(logAuth=='admin'){
			var url=ADMIN_BASE_URL+'users/get-letter-prices';
		}else if(logAuth=='users'){
			var url=BASE_URL+'users/get-letter-prices';
		}
		$.ajax({
			type:'POST',
			url:  url,
			data:{len_letter:lenLetteres},
			success: function(data){
				if(data.output=='success'){
					if(adType=='print_paper'){
						$("#price_leeters_paper").html('&nbsp;'+data.amount+' Rs');
						$("#paper_letter_price").val(data.amount);
					}else if(adType=='ad_magazine'){
						$("#price_leeters_magazine").html('&nbsp;'+data.amount+' Rs');
						$("#magazine_letter_price").val(data.amount);
					}else if(adType=='ad_homedelivery'){
						$("#price_leeters_home").html('&nbsp;'+data.amount+' Rs');
						$("#home_letter_price").val(data.amount);
					}					
				}
			}
		});
	}
}
function getSubcategories(regAuth){	
	if($("#dropCategory").val()!=''){
		var cat_id=$("#dropCategory").val();
	}else{
		var cat_id='';
	}	
	var sess_sub_cat='';
	 if($("#session_sub_cat").val()!=''){
		 sess_sub_cat=$("#session_sub_cat").val();	
	}else{
		sess_sub_cat='';
	}
	if(regAuth=='users'){
		var url=BASE_URL+'users/get-sub-categories';
	}else if(regAuth=='admin'){
		var url=ADMIN_BASE_URL+'users/get-sub-categories';
	}
	if(cat_id!=""){
		$.ajax({
			type:'POST',
			url:  url,
			data:{cat_id:cat_id,sesss_sub_cat:sess_sub_cat},
			success: function(data){
				if(data.output=='success'){
					$("#dropSubCategory").html(data.sub_categories);
				}
			}
		});
	}
}
function addDimensions(){
	var width=$("#image_dimension_w").val();
	var height=$("#image_dimension_h").val();
	var dimension_amount=$("#dimension_amount").val();
	var num_id=$("#hid_num").val();
	if(width==''){
		alert(add_DimentionWidthEmptyMsg);return false;
	}
	if(height==''){
		alert(add_DimentionHeightEmptyMsg);return false;
	}	
	if(dimension_amount==''){
		alert(add_DimentionAmountEmptyMsg);return false;
	}else if(isNaN(dimension_amount)){
			alert(amountNumberFormatMsg);return false;
	}
	$("#add_image_dimension_form").submit();
}
function addDayType(){
	if($("#day_type").val()==''){
		alert(day_amountDateTypeEmptyMsg);return false;
	}
	if($("#day_amount").val()==''){
		alert(day_amountAmountEmptyMsg);return false;
	}else if(isNaN($("#day_amount").val())){
			alert(amountNumberFormatMsg);return false;
	}
	$("#add_day_form").submit();
}
function add_radius(){
	if($("#distance").val()==''){
		alert(add_radiusDistanceEmptyMsg);return false;
	}
	if($("#distance_amount").val()==''){
		alert(add_radiusAmountEmptyMsg);return false;
	}else if(isNaN($("#distance_amount").val())){
			alert(amountNumberFormatMsg);return false;
	}
	$("#add_radius_form").submit();
}
function getAreasLocations(){
	var dist=$("#districts").val();
	
	if(dist=="")
	{
		alert(location_listSelectDistictMsg);return false;
	}
	if($("#area_id").val()!="")
	{
		var area=$("#area_id").val();
	}else if($("#area_id").val()==''){
		var area='';
	}	
	if(dist!='' && area!=''){
		$("#dist_area").attr("href", ADMIN_BASE_URL+"admin/add-locations?dist_id="+dist+"&area_id="+area);
		executeGrid(ADMIN_BASE_URL+'admin/totallocations?dist_id='+dist+'&area_id='+area,'All');
	}else if(area==''){
		$("#dist_area").attr("href", ADMIN_BASE_URL+"admin/add-locations?dist_id="+dist);
		executeGrid(ADMIN_BASE_URL+'admin/totallocations?dist_id='+dist,'All');
	}else{
		$("#dist_area").attr("href", ADMIN_BASE_URL+"admin/add-locations");
		executeGrid(ADMIN_BASE_URL+'admin/totallocations','All');
	}	
}
function getDistrictAreas(page,call_time_locations){
	var sess_area_id='';	
	if($("#districts").val()!="")
	{
		var dist=$("#districts").val();
	}else{
		var dist='';
	}
	if($("#add_url_area_id").val()!="")
	{
		var url_area_id=$("#add_url_area_id").val();
	}else{
		var url_area_id='';
	}
	if(page=='location'){
		if(dist!=''){
			$("#dist_area").attr("href", ADMIN_BASE_URL+"admin/add-locations?dist_id="+dist);
		}else{
			$("#dist_area").attr("href", ADMIN_BASE_URL+"admin/add-locations");
		}
	}
	if(page=='paper'){ 
		if(dist!=''){ 
			$("#dist_area_loca").attr("href", ADMIN_BASE_URL+"admin/paper-population?dist_id="+dist);
		}else{
			$("#dist_area_loca").attr("href", ADMIN_BASE_URL+"admin/paper-population");
		}
	}
	if(page=='user_dist_areas'){
		var url=BASE_URL+'admin/get-areas';
	}else 
	if(page=='f_Areas'){
		var url=BASE_URL+'admin/get-areas';
		if($("#session_area_id").val()!=""){
			var sess_area_id=$("#session_area_id").val();
		}
	}else if(page=='a_Areas'){
		var url=ADMIN_BASE_URL+'admin/get-areas';
		if($("#session_area_id").val()!=""){
			var sess_area_id=$("#session_area_id").val();
		}
	}else{
		var url=ADMIN_BASE_URL+'admin/get-areas';
	}
	if(page=='admin_dist_areas'){
		var url=ADMIN_BASE_URL+'admin/get-areas';
	}
	
	$.ajax({
		type:'POST',
		url:  url,
		data:{dist_id:dist,areas_id:url_area_id,sess_area_id:sess_area_id},
		success: function(data){
			if(page=='location'){				
				$("#area_id").html(data.list_areas);
				if(dist!=''){
					executeGrid(ADMIN_BASE_URL+'admin/totallocations?dist_id='+dist,'All');
				}else{
					executeGrid(ADMIN_BASE_URL+'admin/totallocations','All');
				}				
			}else if(page=='district'){
				$("#areas").html(data.list_areas);
			}else if(page=='paper'){
				$("#areas").html(data.list_areas);
				if(dist!=''){
					executeGrid(ADMIN_BASE_URL+'admin/totalpapers?dist_id='+dist,'All');
				}else{
					executeGrid(ADMIN_BASE_URL+'admin/totalpapers','All');
				}	
			}else if(page=='f_Areas'){
				$("#areas").html(data.list_areas);
				if(call_time_locations=='initial'){
					getAreaBasedLocations('f_Location');
				}		
			}else if(page=='a_Areas'){
				$("#areas").html(data.list_areas);
				if(call_time_locations=='initial'){
					getAreaBasedLocations('a_Location');
				}		
			}else if(page=='admin_dist_areas'){
				$("#areas").html(data.list_areas);
			}else if(page=='user_dist_areas'){
				$("#areas").html(data.list_areas);
			}
		}
	});
}

function getAreaBasedLocations(page){
	var ses_location_id='';
	var dist=$("#districts").val();	
	if(dist=="")
	{
		alert('Please select a district');return false;
	}
	var area=$("#areas").val();	
	if(page!='paper' && page!='f_Location' && page!='a_Location'){
		if(area=="")
		{
			alert('Please select a area');return false;
		}
	}
	if(page=='paper'){
		if(dist!='' && area!=""){
			$("#dist_area_loca").attr("href", ADMIN_BASE_URL+"admin/paper-population?dist_id="+dist+"&area_id="+area);
		}else if(dist!=''){
			$("#dist_area_loca").attr("href", ADMIN_BASE_URL+"admin/paper-population?dist_id="+dist);
		}else{
			$("#dist_area_loca").attr("href", ADMIN_BASE_URL+"admin/paper-population");
		}
	}
	if($("#add_url_location_id").val()!="")
	{
		var url_loca_id=$("#add_url_location_id").val();
	}else{
		var url_loca_id='';
	}
	if(page=='user_area_locations'){
		var url=BASE_URL+'admin/get-locations';
	} else
	if(page=='f_Location'){
		if($("#session_location_id").val()!=''){
			ses_location_id=$("#session_location_id").val();
		}else{
			ses_location_id='';
		}
		var url=BASE_URL+'admin/get-locations';
	}else if(page=='a_Location'){
		if($("#session_location_id").val()!=''){
			ses_location_id=$("#session_location_id").val();
		}else{
			ses_location_id='';
		}
		var url=ADMIN_BASE_URL+'admin/get-locations';
	} else{
		var url=ADMIN_BASE_URL+'admin/get-locations';
	}
	if(page=='admin_area_locations'){
		var url=ADMIN_BASE_URL+'admin/get-locations';
	}
	
	$.ajax({
		type:'POST',
		url:  url,
		data:{dist_id:dist,area_id:area,location_id:url_loca_id,ses_location_id:ses_location_id},
		success: function(data){			
			if(page=='admin_area_locations'){
				$("#location_id").html(data.loca_list);				
			}else if(page=='user_area_locations'){
				$("#location_id").html(data.loca_list);
			}else if(page=='a_Location'){
				$("#location").html(data.loca_list);
				getLocationBasedPaper('a_Paper');
			}else if(page=='f_Location'){
				$("#location").html(data.loca_list);
				getLocationBasedPaper('f_Paper');
			}else if(page=='paper'){
				if(dist!='' && area!=''){
					$("#location").html(data.loca_list);
					executeGrid(ADMIN_BASE_URL+'admin/totalpapers?dist_id='+dist+'&area_id='+area,'All');
				}else if(area==''){
					executeGrid(ADMIN_BASE_URL+'admin/totalpapers?dist_id='+dist,'All');
				}
			}
		}
	});
}
function areasBasedLocations(){
	var dist=$("#districts").val();	
	var area=$("#areas").val();	
	var location_id='';	
	var ses_location_id='';	
	var url=ADMIN_BASE_URL+'admin/get-locations';
	$.ajax({
		type:'POST',
		url:  url,
		data:{dist_id:dist,area_id:area,location_id:location_id,ses_location_id:ses_location_id},
		success: function(data){
			$("#location").html(data.loca_list);
		}
	});
}
function getLocationBasedPaper(page){
	var area=$("#areas").val();
	var dist=$("#districts").val();
	if($("#location").val()!=''){
		var location=$("#location").val();
	}else{
		var location='';
	}
	if(page=='f_Paper'){
		if($("#session_paper_id").val()!=""){
			var ses_paper_id=$("#session_paper_id").val();
		}else{
			var ses_paper_id='';
		}		
		var url=BASE_URL+'admin/get-papers';
	}else if(page=='a_Paper'){
		if($("#session_paper_id").val()!=""){
			var ses_paper_id=$("#session_paper_id").val();
		}else{
			var ses_paper_id='';
		}		
		var url=ADMIN_BASE_URL+'admin/get-papers';
	}else{
		var url=ADMIN_BASE_URL+'admin/get-papers';
	}
	$.ajax({
		type:'POST',
		url:  url,
		data:{dist_id:dist,area_id:area,location_id:location,ses_paper_id:ses_paper_id},
		success: function(data){
			if(data.output=='success'){
				$("#populationpaperdrop").html(data.paper_list);
			}
		}
	});
}
function getLocationPapers(){
	var dist=$("#districts").val();	
	if(dist=="")
	{
		alert('Please select a district');return false;
	}
	if($("#areas").val()!="")
	{
		var area=$("#areas").val();
	}else if($("#areas").val()==''){
		var area='';
	}
	if($("#location").val()!="")
	{
		var local=$("#location").val();
	}else if($("#location").val()==''){
		var local='';
	}
	if(dist!='' && area!='' && local!=''){
		$("#dist_area_loca").attr("href", ADMIN_BASE_URL+"admin/paper-population?dist_id="+dist+"&area_id="+area+"&location_id="+local);
		executeGrid(ADMIN_BASE_URL+'admin/totalpapers?dist_id='+dist+'&area_id='+area+'&location_id='+local,'All');		
	}else if(dist!='' && area!='' && local==''){
		$("#dist_area_loca").attr("href", ADMIN_BASE_URL+"admin/paper-population?dist_id="+dist+"&area_id="+area);
		executeGrid(ADMIN_BASE_URL+'admin/totalpapers?dist_id='+dist+'&area_id='+area,'All');
	}else if(area=='' && local==''){
		$("#dist_area").attr("href", ADMIN_BASE_URL+"admin/paper-population?dist_id="+dist);
		executeGrid(ADMIN_BASE_URL+'admin/totalpapers?dist_id='+dist,'All');
	}else{
		$("#dist_area_loca").attr("href", ADMIN_BASE_URL+"admin/paper-population");
		executeGrid(ADMIN_BASE_URL+'admin/totalpapers','All');
	}	
}
function populationPaper(){
	var dist=$("#districts").val();	
	if(dist=="")
	{
		alert('Please select a district');return false;
	}
	if($("#areas").val()!="")
	{
		var area=$("#areas").val();
	}else if($("#areas").val()==''){
		var area='';
	}
	if($("#location").val()!="")
	{
		var local=$("#location").val();
	}else if($("#location").val()==''){
		var local='';
	}
	if($("#paper").val()!="")
	{
		var paper_id=$("#paper").val();
	}else if($("#paper").val()==''){
		var paper_id='';
	}
	if(dist!='' && area!='' && local!='' && paper_id!=''){
		$("#dist_area_loca").attr("href", ADMIN_BASE_URL+"admin/paper-population?dist_id="+dist+"&area_id="+area+"&location_id="+local+"&paper_id="+paper_id);
		executeGrid(ADMIN_BASE_URL+'admin/totalpapers?dist_id='+dist+'&area_id='+area+'&location_id='+local+'&paper_id='+paper_id,'All');		
	}else if(dist!='' && area!='' && local!='' && paper_id==''){
		$("#dist_area_loca").attr("href", ADMIN_BASE_URL+"admin/paper-population?dist_id="+dist+"&area_id="+area+"&paper_id="+paper_id);
		executeGrid(ADMIN_BASE_URL+'admin/totalpapers?dist_id='+dist+'&area_id='+area+'&paper_id'+paper_id,'All');
	}else if(dist!='' && area!='' && local=='' && paper_id==''){
		$("#dist_area_loca").attr("href", ADMIN_BASE_URL+"admin/paper-population?dist_id="+dist+"&area_id="+area);
		executeGrid(ADMIN_BASE_URL+'admin/totalpapers?dist_id='+dist+'&area_id='+area,'All');
	}else if(area=='' && local=='' && paper_id==''){
		$("#dist_area").attr("href", ADMIN_BASE_URL+"admin/paper-population?dist_id="+dist);
		executeGrid(ADMIN_BASE_URL+'admin/totalpapers?dist_id='+dist,'All');
	}else{
		$("#dist_area_loca").attr("href", ADMIN_BASE_URL+"admin/paper-population");
		executeGrid(ADMIN_BASE_URL+'admin/totalpapers','All');
	}
}
function add_paper(){
	var dist=$("#districts").val();
	var area=$("#areas").val();
	var location=$("#location").val();
	if(dist=="")
	{
		alert(paper_DistrictEmptyMsg);return false;
	}
	if(area=="")
	{
		alert(paper_AreaEmptyMsg);return false;
	}
	if(location=="")
	{
		alert(paper_LocationEmptyMsg);return false;
	}
	if($("#paper_name"+i).val()=='' ){
		alert(paper_paperEmptyMsg);return false;
	}
	if($("#cnt_paper"+i).val()==''){
		alert(paper_CountPaperEmptyMsg);return false;
	}
	$("#paper_form").submit();
}
function add_cat(){
	if($("#cat_name").val()==''){
		alert(add_CategoryEmptyMsg);return false;
	}
	$("#add_cat_form").submit();
}
function add_sub_categories(){
	if($("#category_name").val()==''){
		alert(sub_CategoryEmptyMsg);return false;
	}
	if($("#name"+i).val()==''){
		alert(sub_CategorySubCategoryEmptyMsg);return false;
	}
	$("#sub_cat_form").submit();
}
function add_dist(){
	if($("#dist_name").val()==''){
		alert(add_DistrictEmptyMsg);return false;
	}
	$("#add_dist_form").submit();
}
function add_area(){
	if($("#districts").val()==''){
		alert(add_AreaDistictEmptyMsg);return false;
	}
	if($("#area"+i).val()==''){
		alert(add_AreaAreaEmptyMsg);return false;
	}
	$("#area_form").submit();
}
function change_Dist_Areas(){
	var selectedDist = $("#district_id").val();
	if(selectedDist!=''){
		$("#add_dist_id").attr("href", ADMIN_BASE_URL+"admin/add-area?dist_id="+selectedDist);
	}else{
		$("#add_dist_id").attr("href", ADMIN_BASE_URL+"admin/add-area");
	}
	if(selectedDist!=''){
		executeGrid(ADMIN_BASE_URL+'admin/totalarealists?dist_id='+selectedDist,'All');
	}else{
		executeGrid(ADMIN_BASE_URL+'admin/totalarealists','All');
	}
}
function add_location(){
	if($("#districts").val()==''){
		alert(add_LocationDistictEmptyMsg);return false;
	}
	if($("#areas").val()==''){
		alert(add_LocationAreaEmptyMsg);return false;
	}
	if($("#area"+i).val()==''){
		alert(add_LocationLocationEmptyMsg);return false;
	}
	$("#location_form").submit();
}
function add_num_words(){
	var form_num=$("#num_words").val();
	var to_num=$("#to_num_words").val();
	var num_id=$("#hid_num").val();
	if(form_num==''){
		alert(add_numberwordsFromEmptyMsg);return false;
	}
	if(to_num==''){
		alert(add_numberwordsTOEmptyMsg);return false;
	}
	if(form_num==to_num){
		alert(add_numberwordsFromToMatchMsg);return false;
	}
	if(parseInt(form_num) > parseInt(to_num)){
		alert(fromlessthantoMatchMsg);return false;
	}	
	if($("#num_amounts").val()==''){
		alert(add_numberwordsAmountEmptyMsg);return false;
	}else if(isNaN($("#num_amounts").val())){
			alert(amountNumberFormatMsg);return false;
	}
	if(num_id!=""){
		$("#add_num_form").submit();	
	}else{
		$.ajax({
			type:'POST',
			datatype:'json',
			url:   ADMIN_BASE_URL+'admin/add-numberwords',
			data:{form_num:form_num,to_num:to_num},
			success: function(data){
				if(data.output=='success'){
					alert(fromtoalreadyexistsMatchMsg);return false;
				}else if(data.output=='notsuccess'){
					$("#add_num_form").submit();
				}
			}
		});	
	}	
}
function add_period_package(){
	if($("#period_name").val()==''){
		alert(add_period_packagePeriodEmptyMsg);return false;
	}
	if($("#period_amount").val()==''){
		alert(add_period_packagePeriodAmountEmptyMsg);return false;
	}else if(isNaN($("#period_amount").val())){
			alert(amountNumberFormatMsg);return false;
	}
	
	$("#add_period_form").submit();
}
function add_ads_type(){
	if($("#ads_type_name").val()==''){
		alert(add_ads_typeEmptyMsg);return false;
	}		
	$("#add_ads_form").submit();
}
function userRegister(){
}
function validateadminLogin(){
	var userEmail=$('#inputEmail').val();
	var userPassword=$('#password').val();
	var hid=$('#mod_type').val();
	if(userEmail==''){
		alert(emailEmptyMsg);return false;
	}else if(checkEmail(userEmail)==false){
		alert(emailFormatMsg);return false;
	}
	if(userPassword==''){
		alert(login_PasswordEmptyMsg);return false;
	}
	$('#reload').html('<img src="public/images/spiffygif.gif"/>');
	if(hid=="reg_user"){
		var url=BASE_URL+'admin/admin-login';
	}else{
		var url=ADMIN_BASE_URL+'admin/admin-login';
	}
	$.ajax({
		type:'POST',
		datatype:'json',
		url:  url,
		data:{inputEmail:userEmail,password:userPassword,hid:hid},
		success: function(data){
			$('#reload').html('');
			if(data.output=='success'){
				if(hid=="reg_user"){
					window.location=BASE_URL+'edit-user?user_id='+data.user_id;
				}else{
					window.location=ADMIN_BASE_URL+'admin/add-types';
				}
			}else{
				alert(login_AdimnErrorMsg);return false;
			}
		}
	});
}
function changePassword(regAuth){	
	var userId=$("#hid_user_id").val();	
	var oldpasswrd=$("#oldpwd").val();		
	var passwrd=$("#newpwd").val();
	var cnfpwrd=$("#confirm-pwd").val();
	if(oldpasswrd==""){
		alert(change_passwordOldpwdEmptyMsg);return false;
		$("#oldpwd").focus();
	}		
	if(passwrd==""&& cnfpwrd==""){
		alert(change_passwordNewConfirmEmptyMsg);return false;
		$("#newpwd").focus();
	}	
	if(passwrd==cnfpwrd){
		if(regAuth=='admin'){
			var  url =   ADMIN_BASE_URL+'admin/check-password';
		} else if(regAuth=='user'){
			var  url =  BASE_URL+'users/check-password';
		}
		$.ajax({
			type:'POST',
			url: url,
			data:{oldpasswrd:oldpasswrd,userId:userId},
			success: function(data){
				if(data.output=='success'){	
					if(regAuth=='admin'){
							var  url2 =   ADMIN_BASE_URL+'admin/changepassword';
					} else if(regAuth=='user'){
							var  url2 =  BASE_URL+'users/changepassword';
					}
					$.ajax({
						type:'POST',
						url: url2, 
						data:{cnfpwrd:cnfpwrd,userId:userId},
						success: function(data){
							if(regAuth=='admin'){
								window.location=ADMIN_BASE_URL+'admin/user-lists';
							}else if(regAuth=='user'){
								window.location=BASE_URL+'users/change-password';
							}
							alert(change_passwordSucessMsg);return false;
						}
					});					
				}else{
					alert(change_passwordErrorMsg);return false;
				}
			}
		});					
	}else{
		alert(change_passwordNotmatchedMsg);return false;
		$("#confirm-pwd").focus();
	}	
}	
function forgetPassword(regAuth){	
    var flag=true;
	var emailcheck=$('#forgetMail').val();
	if(emailcheck==''){
		alert(emailEmptyMsg);return false;
	}else if(checkEmail(emailcheck)==false){
		alert(emailFormatMsg);return false;
	}
	if(flag==false){ 
		return false;
	}else{	
		$("#submit").attr("disabled","disabled");
		if(regAuth=='admin'){
			var  url =   ADMIN_BASE_URL+'users/send-password-reset-url';
		} else if(regAuth=='user'){
			var  url =  BASE_URL+'users/send-password-reset-url';
		}
		$.ajax({
			type:'POST',
			url:   url,
			data:{email:emailcheck},
			success: function(data){
				if(data.output=='success'){	
					alert(forget_passwordSuccessMsg);
					if(regAuth=='admin'){
						window.location=ADMIN_BASE_URL+'admin';
					} else if(regAuth=='user'){
						window.location=BASE_URL;
					}
				}else if(data.output=='notsuccess'){
					$('#submit').removeAttr('disabled');
					alert(forget_passwordErrorMsg);return false;
				}else if(data.output=='server-error'){
					$('#submit').removeAttr('disabled');
					alert(forget_passwordServerErrorMsg);return false;
				}
			}
		});						
	}		
}
function getUsersBasedonusertype(){ 
	var user_type_id=$("#user_type_id").val();
	if(user_type_id!=''){
		executeGrid(ADMIN_BASE_URL+'admin/totaluserlists?user_type_id='+user_type_id,'All');
	}else{
		executeGrid(ADMIN_BASE_URL+'admin/totaluserlists','All');
	}	
}	
function francheseShow(){
	var user_type=$("#user_type").val();
	if(user_type==2){
		$("#franchesediv").show();
	}
	if(user_type==3){
		$("#franchesediv").hide();
	}
}
function adduserValidations(regBy){
		var user_name=$("#inputUserName").val();
		var user_email=$("#inputEmail").val();
		var user_password=$("#password").val();
		var user_phnnum=$("#phoneNumber").val();
		var user_address=$("#address").val();
		var user_type=$("#user_type").val();
		var franchese_district=$("#districts").val();
		var franchese_area=$("#areas").val();
		var franchese_location=$("#location_id").val();
		if(user_type==''){
			alert(add_userUserTypeMsg);return false;
		}
		if(user_name==''){
			alert(add_userNameEmptyMsg);return false;
		}
		if(user_email==''){
			alert(emailEmptyMsg);return false;
		}else if(checkEmail(user_email)==false){
			alert(emailFormatMsg);return false;
		}if(user_password==''){
			alert(add_userPasswordEmptyMsg);return false;
		}
		if(user_phnnum==''){
			alert(phoneNumberEmptyMsg);return false;
		}else if(isNaN(user_phnnum)){
			alert(phoneNumberFormatMsg);return false;
		}
		if(user_address==''){
			alert(edit_userAddressEmptyMsg);return false;
		}
		if(user_type==2){
			if(franchese_district==''){
				alert(add_LocationDistictEmptyMsg);return false;
			}
			if(franchese_area==''){
				alert(add_LocationAreaEmptyMsg);return false;
			}
			if(franchese_location==''){
				alert(add_LocationLocationEmptyMsg);return false;
			}
		}
		if(regBy=='admin'){
			var url=ADMIN_BASE_URL+'users/checkregemail';
			if(user_type==''){
				alert(add_userUserTypeMsg);return false;
			}
		}else{
			var url=BASE_URL+"users/checkregemail";
		}
		$.ajax({
			type:'POST',
			datatype:'json',
			url:   url,
			data:{email:user_email},
			success: function(data){
				if(data.output=='success'){
					alert(add_userEmailExistMsg);return false;
				}else if(data.output=='notsuccess'){
					$("#regiserForm").submit();					
				}
			}
		});
}
function edituserValidations(regBy){
	var user_name=$("#inputUserName").val();
	var user_display_name=$("#displayName").val();
	var user_email=$("#inputEmail").val();
	var user_secondmail=$("#secondEmail").val();
	var user_phnnum=$("#phoneNumber").val();
	var user_SecondPhone=$("#alternateNumber").val();
	var user_country=$("#country").val();
	var user_state=$("#state").val();
	var user_district=$("#districts").val();
	var user_area=$("#areas").val();
	var user_cityname=$("#cityname").val();
	var user_address=$("#address").val();
	var user_pincode=$("#pincode").val();
	var franchese_location=$("#location_id").val();
	if(user_name==''){
		alert(add_userNameEmptyMsg);return false;
	}
	if(user_display_name==''){
		alert(edit_userDisplayNameEmptyMsg);return false;
	}
	if(user_email==''){
		alert(emailEmptyMsg);return false;
	}else if(checkEmail(user_email)==false){
		alert(emailFormatMsg);return false;
	}
	if(user_secondmail==''){
		alert(secondaryemailEmptyMsg);return false;
	}else if(checkEmail(user_secondmail)==false){
		alert(secondaryemailFormatMsg);return false;
	}
	if(user_phnnum==''){
		alert(phoneNumberEmptyMsg);return false;
	}else if(isNaN(user_phnnum)){
		alert(phoneNumberFormatMsg);return false;
	}
	if(user_SecondPhone==''){
		alert(alternatePhoneNumberEmptyMsg);return false;
	}else if(isNaN(user_SecondPhone)){
		alert(alternatePhoneNumberFormatMsg);return false;
	}
	if(user_country==''){
		alert(edit_userCountryEmptyMsg);return false;
	}
	if(user_state==''){
		alert(edit_userStateEmptyMsg);return false;
	}
	if(user_district==''){
		alert(edit_userDistrictEmptyMsg);return false;
	}
	if(user_area==''){
		alert(edit_userAreaEmptyMsg);return false;
	}
	if(user_cityname==''){
		alert(edit_userCityNameEmptyMsg);return false;
	}
	if(user_address==''){
		alert(edit_userAddressEmptyMsg);return false;
	}
	if(user_pincode==''){
		alert(edit_userPincodeEmptyMsg);return false;
	}else if(isNaN(user_pincode)){
		alert(edit_userPincodeFormatMsg);return false;
	}
	if(franchese_location==''){
		alert(add_LocationLocationEmptyMsg);return false;
	}
	$("#edit_form").submit();
}
function updatePassword(regAuth){	
	var flag=true;
	var token=$('#hidtoken').val();	
	var passwrd=$("#newpwd").val();
	var cnfpwrd=$("#confirm-pwd").val();		
	if(passwrd==""&& cnfpwrd==""){
		alert(update_passwordNewConfirmEmptyMsg);
		flag=false;
		$("#newpwd").focus();
	}		
	if(flag==false){ 
			return false;
	}else{			
		if(passwrd==cnfpwrd){
		$('#loading').show();
			if(regAuth=='admin'){
					var  url =  ADMIN_BASE_URL+'users/setnepassword';
			} else if(regAuth=='user'){
					var  url = BASE_URL+'users/setnepassword';
			}
			$.ajax({
				type:'POST',
				url:url,
				data:{cnfpwrd:cnfpwrd,token:token},
				success: function(data){
					$('#loading').hide();
					if(data.output=='success'){	
						alert(update_passwordSucessMsg);
						if(regAuth=='admin'){
							window.location=ADMIN_BASE_URL+'admin';
						} else if(regAuth=='user'){
							window.location=BASE_URL;
						}
					}else{
						alert(update_passwordAlreadyUpdateSucessMsg);
					}
				}
			});
		}else{
			alert(update_passwordNotMatchedMsg);
			$("#confirm-pwd").focus();
		}
	}		
}
function testimonyValidate(regAuth){
	var textimony=$("#testimony_text").val();
	if(textimony==''){
		alert(validateTestmony);return false;
	}
	$("#testimony_form").submit();
}
function addListClick(){
	$('#caregorydrop').hide();	
	$('#cat_switching').val(0);
	$('#categoryText').show();
}
function addListBackClick(){
	$('#cat_switching').val(1);
	$('#caregorydrop').show();
	$('#categoryText').hide();
}
function clickAdmode(checkvalue,logAuth){
	if(checkvalue=='Print Paper'){
		document.getElementById("printPaper").checked?$('#printpaperdiv').show():$('#printpaperdiv').hide();
		$('#surcharge_paper').html($('#sur_charge_paper').val());
		$("#start_date").datepicker({
			minDate:0,
			dateFormat: 'yy-mm-dd',
			yearRange: '1900:9999',
			numberOfMonths: 1,
			onSelect: function(selected) {
				var date1 = $('#start_date').datepicker('getDate');
				var date = new Date( Date.parse( date1 ) );
				date.setDate( date.getDate() + 1 );
				var newDate = date.toDateString();
				newDate = new Date( Date.parse( newDate ) );
				var enddate=$("#end_date").val();
				var date=$(this).val();	
				setDatesDiff(date,enddate,'stdate',logAuth);
				$('#end_date').datepicker("option","minDate",newDate);
			}
		});		
		$("#end_date").datepicker({
			dateFormat: 'yy-mm-dd',
			yearRange: '1900:9999',
			numberOfMonths: 1,
			onSelect: function(selected) {
				var today=$("#start_date").val();
				var date=$(this).val();	
				setDatesDiff(today,date,'enddate',logAuth);	
				$("#start_date").datepicker("option","maxDate", selected)
			}
		});	
		$("#slected_days").multiDatesPicker({ 	
			onSelect: function(selected) {
				var dates = $('#slected_days').multiDatesPicker('getDates');				 
				var countDays=dates.length;	
				var weekdays=0;
				var weekends=0;
				var i;
				for(i=0;i<countDays;i++){
					var date=new Date(dates[i]);
					if(parseInt(date.getDay())==parseInt('0') || parseInt(date.getDay())==parseInt('6')){
						weekends++;
					}else{
						weekdays++;
					}
				}
				$("#select_days").html(countDays);
				$("#tot_days").val(countDays);
				$("#weekdays").val(weekdays);
				$("#weekends").val(weekends);
				get_price_week_end(weekdays,weekends,'selected',logAuth);
				$("#weekend_weekdays").html('('+weekdays+' Week Days,'+weekends+' Week Ends)');
			}					
		});
	}else if(checkvalue=='Magazine'){
		document.getElementById("magazineCheck").checked?$('#magazinediv').show():$('#magazinediv').hide(); 
		$('#surcharge_magazine').html($('#sur_charge_magazine').val());
		$("#magazine_start_date").datepicker({
			dateFormat: 'yy-mm-dd',
			yearRange: '1900:9999',
			numberOfMonths: 1,
			minDate:0,
		});			
	}else if(checkvalue=='Home Delivery'){
		document.getElementById("homedelevarycheck").checked?$('#homedelivarydiv').show():$('#homedelivarydiv').hide(); 
		$('#surcharge_home').html($('#sur_charge_home').val());
		$("#home_start_date").datepicker({
			dateFormat: 'yy-mm-dd',
			yearRange: '1900:9999',
			numberOfMonths: 1,
			minDate:0,
		});
	}
}
function setDatesDiff(startdate,enddate,stend,logAuth){
	if(startdate!='' && enddate!=''){
		var dayDiff = Math.ceil((new Date(enddate) - new Date(startdate)) / (1000 * 60 * 60 * 24))+1;
		var stdate=new Date(startdate);
		var eddate=new Date(enddate);
		var end_date_time = eddate.getTime();
		var weekdays=0;
		var weekends=0;
		while(stdate.getTime() <= end_date_time){			
			if(parseInt(stdate.getDay())==parseInt('0') || parseInt(stdate.getDay())==parseInt('6')){
				weekends++;
			}else{
				weekdays++;
			}			
			stdate.setDate(stdate.getDate()+1);
			
		}
		 $("#weekdays_st").val(weekdays);
		 $("#weekends_st").val(weekends);
		 get_price_week_end(weekdays,weekends,'st_et',logAuth);
		$("#weekends_weekdays_st").html('('+weekdays+' Week Days,'+weekends+' Week Ends)');		
	}else{
		var dayDiff='';
	}
	$('#daysId').text('');
	var spans = $('#daysId').text();
	$("#tot_days_st").val(dayDiff);	
	$('#daysId').html(dayDiff);
			
}
function get_price_week_end(weekdays,weekends,dp_type,logAuth) {
	if(logAuth=='admin'){
		var url=ADMIN_BASE_URL+'users/price-days';
	}else if(logAuth=='users'){
		var url=BASE_URL+'users/price-days';
	}
	 $.ajax({
		 type:'POST',
		 url : url,
		 data:{weekday:weekdays,weekend:weekends},
		 success: function(data){
			if(dp_type=='st_et') {
				var total_amouunt= parseInt(data.week_days)+parseInt(data.week_ends);
				$("#week_st_amount").val(total_amouunt+' Rs');
				$('#price_st').html('Weekdays price:'+data.week_days+' Rs'+', Weekends price:'+data.week_ends+' Rs');
			}
			else if(dp_type=='selected') {
				var total_amouunt= parseInt(data.week_days)+parseInt(data.week_ends);
				$("#week_selected_amount").val(total_amouunt+' Rs');
				$('#price_seleted').html(data.week_days+' Rs'+ +data.week_ends+' Rs');
			}
		}
	});
}
function showSelectedDays(){
	$("#start-end").show();
	$("#Selected").hide();
}
function showStartEndDays(){
	$("#start-end").hide();
	$("#Selected").show();
}	
$('#imageMagazineId').click(function(){
	this.checked?$('#imageMagzineSubDiv').show():$('#imageMagzineSubDiv').hide(); 
});
$('#imageDelivarId').click(function(){
	this.checked?$('#imageHomeDelivarSub').show():$('#imageHomeDelivarSub').hide(); 
});

$('#imagePaperId').click(function(){
	this.checked?$('#imagePaperSubDiv').show():$('#imagePaperSubDiv').hide();
});
function add_offers(){
	var offer_name=$("#offer_name").val();
	var offer_amount=$("#offer_amount").val();
	var offer_discount=$("#offer_discount").val();
	var offer_expire=$("#exp_check").val();
	var offer_start_date=$("#start_date").val();
	var offer_end_date_date=$("#end_date").val();
	if(offer_name==''){
		alert(add_offerNameEmptyMsg);return false;
	}
	if(offer_amount==''){
		alert(add_offerAmountEmptyMsg);return false;
	}else if(isNaN(offer_amount)){
			alert(amountNumberFormatMsg);return false;
	}
	if(offer_discount==''){
		alert(add_offerDiscountEmptyMsg);return false;
	}
	if(offer_expire==1){
		if(offer_start_date==''){
			alert(add_offerStartEmptyMsg);return false;
		}
		if(offer_end_date_date==''){
			alert(add_offerEndEmptyMsg);return false;
		}
	}
	$("#add_offer_form").submit();
}
function deleteTestimony(testimonyid){

	if(confirm(deleteRecordCinfirmMsg)){
		window.location=BASE_URL+"users/delete-testimony?testimony_id="+testimonyid;					
	}
}
function radiusAmount(logAuth){
	if($('#radius').val()!=''){
		if(logAuth=='users'){
			var url=BASE_URL+'users/get-radius-prices';
		}else if(logAuth=='admin'){
			var url=ADMIN_BASE_URL+'users/get-radius-prices';
		}
		var radius_id=$('#radius').val();
		 $.ajax({
			 type:'POST',
			 url : url,
			 data:{radius_id:radius_id},
			 success: function(data){
				if(data.output=='success'){
					$("#showRadiusAmount").html(data.amount+' Rs');			
					$("#radius_amount").val(data.amount);			
				}
			 }
		});
	}else{
		$("#showRadiusAmount").html('');
		$("#radius_amount").val('');
	}
}
function getAmount_period(logAuth){
	if(logAuth=='users'){
		var url=BASE_URL+'users/get-period-prices';
	}else if(logAuth=='admin'){
		var url=ADMIN_BASE_URL+'users/get-period-prices';
	}
	if($('#periodtime').val()!=''){
		var period_id=$('#periodtime').val();
		 $.ajax({
			 type:'POST',
			 url : url,
			 data:{period_pakage_id:period_id},
			 success: function(data){
				if(data.output=='success'){
					$("#showPeriodAmount").html(data.amount+' Rs');			
					$("#period_amount").val(data.amount);			
				}
			 }
		});
	}else{
		$("#showPeriodAmount").html('');
		$("#period_amount").val('');
	}
}
function getPaperprice(logAuth){
	if($('#populationpaperdrop').val()!=''){
		if(logAuth=='users'){
			var url=BASE_URL+'users/get-paper-prices';
		}else if(logAuth=='admin'){
			var url=ADMIN_BASE_URL+'users/get-paper-prices';
		}
		var paper_cir_id=$('#populationpaperdrop').val();
		 $.ajax({
			 type:'POST',
			 url : url,
			 data:{paper_cir_id:paper_cir_id},
			 success: function(data){
				if(data.output=='success'){
					$("#showPaperAmount").html(data.amount+' Rs');			
					$("#paper_amount").val(data.amount);			
				}
			 }
		});
	}else{
		$("#showPaperAmount").html('');
		$("#paper_amount").val('');
	}
}
function adPostValidations(regAuth){
	var flag=true;
	var guest_email=$('#guest_email').val();
	var guest_phone=$('#guest_phone').val();
	var lan_id=$('#language').val();
	var cat_id=$('#dropCategory').val();
	var sub_cat_id=$('#dropSubCategory').val();
	var add_cat_id=$('#categoryText').val();
	var add_sub_cat_id=$('#subCategoryText').val();
	var dist_id=$('#districts').val();
	var area_id=$('#areas').val();
	var loc_id=$('#location').val();
	if(regAuth=='frenchsee'){
		if(guest_email==''){
			alert(ad_postingGuestEmailEmptyMsg);return false;
		}
		if(guest_phone==''){
			alert(ad_postingGuestPhoneEmptyMsg);return false;
		}else if(isNaN(guest_phone)){
			alert(ad_postingGuestPhoneNumberMsg);return false;
		}
	}
	if(regAuth=='admin'){
		if(guest_email==''){
			alert(ad_postingGuestEmailEmptyMsg);return false;
		}
		if(guest_phone==''){
			alert(ad_postingGuestPhoneEmptyMsg);return false;
		}else if(isNaN(guest_phone)){
			alert(ad_postingGuestPhoneNumberMsg);return false;
		}
	}
	if(lan_id==''){
		alert(ad_postingLanguageEmptyMsg);return false;		
	}
	if($('#cat_switching').val()=='1'){
		if(cat_id==''){
			alert(ad_postingCategoryEmptyMsg);return false;
		}if(sub_cat_id==''){
			alert(ad_postingSubCategoryEmptyMsg);return false;
		}
	}else if($('#cat_switching').val()=='0'){
		if(add_cat_id==''){
			alert(ad_postingAddCategoryEmptyMsg);return false;
		}if(add_sub_cat_id==''){
			alert(ad_postingAddSubCategoryEmptyMsg);return false;
		}
	}
	if(dist_id==''){
		alert(ad_postingDistictEmptyMsg);return false;
	}if(area_id==''){
		alert(ad_postingAreaEmptyMsg);return false;
	}if(loc_id==''){
		alert(ad_postingLocationEmptyMsg);return false;
	}
	// Paper Printing

	if(document.getElementById("printPaper").checked == false 
	&& document.getElementById("magazineCheck").checked == false
	&& document.getElementById("homedelevarycheck").checked == false){
		alert(ad_postingAdModeTypeSelelectMsg);return false;
	}
	if(document.getElementById("printPaper").checked == true){
		var paper_id=$('#populationpaperdrop').val();
		if(paper_id==''){
			alert(ad_postingpapulationSelelectMsg);return false;		
		}
		var paper_title=$('#title_paper').val();
		if(paper_title==''){
			alert(ad_postingpaperAdTitleEmptyMsg);return false;		
		}
		if(document.getElementById("imagePaperId").checked == true){
			var paper_image=$('#paperupload').val();
			if(paper_image==''){
				alert(ad_postingpaperAdSelectImageMsg);return false;		
			}else if($("#checkImage_paper").val()=='0'){
				alert(ad_postingPaperAdImageMsg);return false;		
			}
		}
		var paper_description=$('#textAreaPaper').val();
		if(paper_description==''){
			alert(ad_postingPaperAdDescriptionEmptyMsg);return false;		
		}
		if($("#optionsRadios1").prop("checked")){
			var start_date=$('#start_date').val();
			if(start_date==''){
				alert(ad_postingPaperAdStartDateSelectMsg);return false;		
			}
			var end_date=$('#end_date').val();
			if(end_date==''){
				alert(ad_postingPaperAdEndDateSelectMsg);return false;		
			}
		}
		if($("#optionsRadios2").prop("checked")){
			var slected_days=$('#slected_days').val();
			if(slected_days==''){
				alert(ad_postingPaperAdSelecteddaysMsg);return false;		
			}
		}	
	}
	
	// Magazine
	if(document.getElementById("magazineCheck").checked == true){
		var magazine_title=$('#titleMagazine').val();
		if(magazine_title==''){
			alert(ad_postingMagazineAdTitleEmptyMsg);return false;		
		}
		if(document.getElementById("imageMagazineId").checked == true){
			var magazine_image=$('#magizenupload').val();
			if(magazine_image==''){
				alert(ad_postingMagazineAdImageEmptyMsg);return false;		
			}else if($("#checkImage_magazine").val()=='0'){
				alert(ad_postingPaperAdImageMsg);return false;		
			}
		}
		var magazine_description=$('#textAreaMagazine').val();
		if(magazine_description==''){
			alert(ad_postingMagazineAdDescriptionEmptyMsg);return false;		
		}
		if($("#magazine_start_date").val()==''){
			alert(ad_postingMagazineAdDelivaryDateEmptyMsg);return false;
		}
		var magazine_periodtime=$('#periodtime').val();
		if(magazine_periodtime==''){
			alert(ad_postingMagazineAdPeriodEmptyMsg);return false;		
		}
	}
	
	// Home Delivery
	if(document.getElementById("homedelevarycheck").checked == true){
		var home_title=$('#titleHome').val();
		if(home_title==''){
			alert(ad_postingHomeDelivarTitleEmptyMsg);return false;		
		}
		if(document.getElementById("imageDelivarId").checked == true){
			var home_image=$('#homeupload').val();
			if(home_image==''){
				alert(ad_postingHomeDelivarAdImageEmptyMsg);return false;		
			}else if($("#checkImage_home").val()=='0'){
				alert(ad_postingPaperAdImageMsg);return false;		
			}
		}
		var home_description=$('#textAreaHome').val();
		if(home_description==''){
			alert(ad_postingHomeDelivarAdDescriptionMsg);return false;		
		}
		if($("#home_start_date").val()==''){
			alert(ad_postingHomeDelivarAdDelivarMsg);return false;
		}
		var home_radius=$('#radius').val();
		if(home_radius==''){
			alert(ad_postingHomeDelivarAdRadiesEmptyMsg);return false;		
		}
	}
	$("#adpost_form").submit();
}
function countNotifications(user_id){
	$.ajax({
		 type:'GET',
		 url : BASE_URL+'users/notificationsUpdate',
		 data:{user_id:user_id},
		 success: function(data){
			if(data.output=='success'){
			$('#countId').removeClass("pos_ab");
			$('#countId').html("");
			window.location=BASE_URL+'users/notifications';
			}
		 }
	});
}
function adOrder(orderBy){
	
	if(orderBy=='users'){
		var url=BASE_URL+'users/order-save';
	}else if(orderBy=='admin'){
		var url=ADMIN_BASE_URL+'admin/order-save';
	}
	if( document.getElementById("ad_mode_offline").checked == false && document.getElementById("ad_mode_online").checked == false){
		alert(confirm_orderSelectMsg);return false;
	}
	window.location=url;
}
function unqiueMode(adMode,logAuth){
	var grandTotal=$("#grand_total").val();
	if(logAuth=='users'){
		var url=BASE_URL+'users/session-update-admode';
	}else if(logAuth=='admin'){
		var url=ADMIN_BASE_URL+'users/session-update-admode';
	}
	if(adMode=='offline'){
		document.getElementById("ad_mode_online").checked =false;		
	}
	if(adMode=='online'){
		document.getElementById("ad_mode_offline").checked =false;
	}
	$.ajax({type:'POST',url : url,data:{adMode:adMode,grandTotal:grandTotal},});
}
function discountOffer(offerId,logAuth){
	if($("#grand_total").val()!=""){
		var garndTotal=$("#grand_total").val();
	}else{
		var garndTotal='';
	}
	if(logAuth=='users'){
		var url=BASE_URL+'users/get-discount-total';
	}else if(logAuth=='admin'){
		var url=ADMIN_BASE_URL+'users/get-discount-total';
	}
	 $.ajax({
		 type:'POST',
		 url : url,
		 data:{garndTotal:garndTotal,offerId:offerId},
		 success: function(data){
			if(data.output=='success'){
				$("#showAlert").show();
				$("#disCountAmount").html('<b>'+data.calDiscount+' RS'+'</b>');
			}else if(data.output=='not success'){
				$("#showAlert").hide();
				alert('Discount not applicable');return false;
			}
		}
	});
}
function franchiseeorderCancel(){
	alert('Sorry! Calcel process is incomplete');
}
function textColorChange(adType,logAuth){	
	if(adType=='paper'){
		if($("#paper_text_color").val()!=''){
			var textColor=$("#paper_text_color").val();
		}else{
			var textColor='#00000';
		}
		$("#textAreaPaper").css("color",textColor);
		$("#paper_text_color_db").val(textColor);
	}else if(adType=='magazine'){
		if($("#magazine_text_color").val()!=''){
			var textColor=$("#magazine_text_color").val();
		}else{
			var textColor='#00000';
		}
		$("#textAreaMagazine").css("color",textColor);
		$("#magazine_text_color_db").val(textColor);
	}else if(adType=='home'){
		if($("#home_text_color").val()!=''){
			var textColor=$("#home_text_color").val();
		}else{
			var textColor='#00000';
		}
		$("#textAreaHome").css("color",textColor);
		$("#home_text_color_db").val(textColor);
	}	
}
function getfranchiseeorders(regAuth,adMode){
	var user_id=$("#f_u_id").val();
	var cat_id=$("#dropCategory").val();
	var sub_cat_id=$("#dropSubCategory").val();
	if(user_id!='' && cat_id=='' && sub_cat_id==''){
		executeGrid(ADMIN_BASE_URL+'admin/totalonlineorders?admode='+adMode+'&user_id='+user_id,'All');
	}else if(user_id!='' && cat_id!='' && sub_cat_id==''){
		executeGrid(ADMIN_BASE_URL+'admin/totalonlineorders?admode='+adMode+'&user_id='+user_id+'&cat_id='+cat_id,'All');
	}else if(user_id!='' && cat_id!='' && sub_cat_id!=''){
		executeGrid(ADMIN_BASE_URL+'admin/totalonlineorders?admode='+adMode+'&user_id='+user_id+'&cat_id='+cat_id+'&sub_cat_id='+sub_cat_id,'All');
	}else if(user_id=='' && cat_id!='' && sub_cat_id==''){          
		executeGrid(ADMIN_BASE_URL+'admin/totalonlineorders?admode='+adMode+'&cat_id='+cat_id,'All');
	}else if(user_id=='' && cat_id!='' && sub_cat_id!=''){          
		executeGrid(ADMIN_BASE_URL+'admin/totalonlineorders?admode='+adMode+'&cat_id='+cat_id+'&sub_cat_id='+sub_cat_id,'All');
	}else if(user_id=='' && cat_id=='' && sub_cat_id==''){          
		executeGrid(ADMIN_BASE_URL+'admin/totalonlineorders?admode='+adMode,'All');
	}
}
function getgridsubcategories(regAuth,adMode){	
	var user_id=$("#f_u_id").val();
	if($("#dropCategory").val()!=''){
		var cat_id=$("#dropCategory").val();
	}else{
		var cat_id='';
	}	
	var sess_sub_cat='';	
	var url=ADMIN_BASE_URL+'users/get-sub-categories';
	$.ajax({
		type:'POST',
		url:  url,
		data:{cat_id:cat_id,sesss_sub_cat:sess_sub_cat},
		success: function(data){
			if(data.output=='success'){
				$("#dropSubCategory").html(data.sub_categories);
				if(user_id!='' && cat_id==''){
					executeGrid(ADMIN_BASE_URL+'admin/totalonlineorders?admode='+adMode+'&user_id='+user_id,'All');
				}else if(user_id!='' && cat_id!=''){
					executeGrid(ADMIN_BASE_URL+'admin/totalonlineorders?admode='+adMode+'&user_id='+user_id+'&cat_id='+cat_id,'All');
				}else if(user_id=='' && cat_id!=''){
					executeGrid(ADMIN_BASE_URL+'admin/totalonlineorders?admode='+adMode+'&cat_id='+cat_id,'All');
				}else if(user_id=='' && cat_id==''){
					executeGrid(ADMIN_BASE_URL+'admin/totalonlineorders?admode='+adMode,'All');
				}
			}
		}
	});	
}
function getusergridsubcategories(regAuth,adMode){	
	var user_id=$("#ordertypeid").val();
	if($("#category").val()!=''){
		var cat_id=$("#category").val();
	}else{
		var cat_id='';
	}	
	var sess_sub_cat='';	
	var url=BASE_URL+'users/get-sub-categories';
	$.ajax({
		type:'POST',
		url:  url,
		data:{cat_id:cat_id,sesss_sub_cat:sess_sub_cat},
		success: function(data){
			if(data.output=='success'){
				$("#subcategoryid").html(data.sub_categories);
				if(user_id!='' && cat_id==''){
					var query=BASE_PATH+'/users/userorderviewAjax?ordertype='+user_id;
				}else if(user_id!='' && cat_id!=''){
					var query=BASE_PATH+'/users/userorderviewAjax?ordertype='+user_id+'&cid='+cat_id;
				}else if(user_id=='' && cat_id!=''){
					var query=BASE_PATH+'/users/userorderviewAjax?cid='+cat_id;
				}else if(user_id=='' && cat_id==''){
					var query=BASE_PATH+'/users/userorderviewAjax';
				}
				$.ajax({
					type:'GET',
					dataType:'json',
					url:query,
					success: function(data){
					$('.product_table').html('<table  class="table table-bordered" cellpadding="0" cellspacing="0" width="100%" id="search_results"><thead><tr class="bg_header"><th>OrderId</th><th>Username</th><th>PhoneNumber</th><th>Amount</th><th>Offline/Online</th><th>PaymentStatus</th><th>OrderStatus</th><th>Action</th></tr></thead><tbody></tbody></table>');	
						if(data!='1'){
							eval(data);
							var oTable = $('#search_results').dataTable( {
								aoColumnDefs: [{bSortable: false,
												aTargets: [ 0 ]
												}],
								"bStateSave": true,
								"bAutoWidth": true,
								"sRowSelect": "multi",
								"sPaginationType": "full_numbers",
								"bProcessing": true,
								"aaData": data,
								"aoColumns": [
									{ "mData": "order_id" },
									{ "mData": "user_name" },
									{ "mData": "phone_number" },
									{ "mData": "amount" },						
									{ "mData": "admode" },						
									{ "mData": "payment_status" },						
									{ "mData": "order_status" },
									{ "mData": "Action" }
								] 
							});
						}else{
							$('.product_table').html('No Data is available...');	
						}					
					}
				});
				
			}
		}
	});	
}
function changeUserOrder(regAuth){
	$('.product_table').html('Please wait loading....');
	var ordertype=$('#ordertypeid').val();
	var cid=$('#category').val();
	var scid=$('#subcategoryid').val();
	if(ordertype!='' && cid=='' && scid==''){
		var query=BASE_PATH+'/users/userorderviewAjax?ordertype='+ordertype;
	}else if(ordertype!='' && cid!='' && scid==''){
		var query=BASE_PATH+'/users/userorderviewAjax?ordertype='+ordertype+'&cid='+cid;
	}else if(ordertype!='' && cid!='' && scid!=''){
		var query=BASE_PATH+'/users/userorderviewAjax?ordertype='+ordertype+'&cid='+cid+'&scid='+scid;
	}else if(ordertype=='' && cid!='' && scid==''){
		var query=BASE_PATH+'/users/userorderviewAjax?cid='+cid;
	}else if(ordertype=='' && cid!='' && scid!=''){
		var query=BASE_PATH+'/users/userorderviewAjax?cid='+cid+'&scid='+scid;
	}else if(ordertype=='' && cid=='' && scid==''){
		var query=BASE_PATH+'/users/userorderviewAjax';
	}
	$.ajax({
		type:'GET',
		dataType:'json',
		url:query,
		success: function(data){
		$('.product_table').html('<table  class="table table-bordered" cellpadding="0" cellspacing="0" width="100%" id="search_results"><thead><tr class="bg_header"><th>OrderId</th><th>Username</th><th>PhoneNumber</th><th>Amount</th><th>Offline/Online</th><th>PaymentStatus</th><th>OrderStatus</th><th>Action</th></tr></thead><tbody></tbody></table>');	
			if(data!='1'){
				eval(data);
				var oTable = $('#search_results').dataTable( {
					aoColumnDefs: [{bSortable: false,
									aTargets: [ 0 ]
									}],
					"bStateSave": true,
					"bAutoWidth": true,
					"sRowSelect": "multi",
					"sPaginationType": "full_numbers",
					"bProcessing": true,
					"aaData": data,
					"aoColumns": [
						{ "mData": "order_id" },
						{ "mData": "user_name" },
						{ "mData": "phone_number" },
						{ "mData": "amount" },						
						{ "mData": "admode" },						
						{ "mData": "payment_status" },						
						{ "mData": "order_status" },
						{ "mData": "Action" }
					] 
				});
			}else{
				$('.product_table').html('No Data is available...');	
			}					
		}
	});
}
function changecategoryuserFranchiseeOrder(regAuth,paymenttype){
	$('.product_table').html('Please wait loading....');
	var scid=$('#subcategoryid').val();
	if($("#category").val()!=''){
		var cat_id=$("#category").val();
	}else{
		var cat_id='';
	}
	var sess_sub_cat='';
	var url=BASE_URL+'users/get-sub-categories';
	$.ajax({
		type:'POST',
		url:  url,
		data:{cat_id:cat_id,sesss_sub_cat:sess_sub_cat},
		success: function(data){
			if(data.output=='success'){
				$("#subcategoryid").html(data.sub_categories);
				if(regAuth=='ordesonline'){
					if( cat_id!=''){
						var query=BASE_PATH+'/users/order-view-ajax?cid='+cat_id+'&payment_mode='+paymenttype;
					}else if(cat_id==''){
						var query=BASE_PATH+'/users/order-view-ajax?payment_mode='+paymenttype;
					}
				}else{
					if( cat_id!=''){
						var query=BASE_PATH+'/users/order-offline-view-ajax?cid='+cat_id+'&payment_mode='+paymenttype;
					}else if(cat_id==''){
						var query=BASE_PATH+'/users/order-offline-view-ajax?payment_mode='+paymenttype;
					}
				}
				if(regAuth=='ordesonline'){
					$.ajax({
						type:'GET',
						dataType:'json',
						url:query,
						success: function(data){
						$('.product_table').html('<table  class="table table-bordered" cellpadding="0" cellspacing="0" width="100%" id="search_results"><thead><tr class="bg_header"><th>OrderId</th><th>Username</th><th>PhoneNumber</th><th>Amount</th><th>PaymentStatus</th><th>OrderStatus</th></tr></thead><tbody></tbody></table>');	
							if(data!='1'){
								eval(data);
								var oTable = $('#search_results').dataTable( {
									aoColumnDefs: [{bSortable: false,
													aTargets: [ 0 ]
													}],
									"bStateSave": true,
									"bAutoWidth": true,
									"sRowSelect": "multi",
									"sPaginationType": "full_numbers",
									"bProcessing": true,
									"aaData": data,
									"aoColumns": [
										{ "mData": "order_id" },
										{ "mData": "user_name" },
										{ "mData": "phone_number" },
										{ "mData": "amount" },	
										{ "mData": "payment_status" },						
										{ "mData": "order_status" }
									] 
								});
							}else{
								$('.product_table').html('No Data is available...');	
							}					
						}
					});
				}else{
					$.ajax({
						type:'GET',
						dataType:'json',
						url:query,
						success: function(data){
							$('.product_table').html('<table  class="table table-bordered" cellpadding="0" cellspacing="0" width="100%" id="search_results"><thead><tr class="bg_header"><th>OrderId</th><th>Username</th><th>PhoneNumber</th><th>Amount</th><th>DueAmount</th><th>PaymentStatus</th><th>OrderStatus</th><th>Action</th></tr></thead><tbody></tbody></table>');	
							if(data!='1'){
								eval(data);
								var oTable = $('#search_results').dataTable( {
									aoColumnDefs: [{bSortable: false,
													aTargets: [ 0 ]
													}],
									"bStateSave": true,
									"bAutoWidth": true,
									"sRowSelect": "multi",
									"sPaginationType": "full_numbers",
									"bProcessing": true,
									"aaData": data,
									"aoColumns": [
									{ "mData": "order_id" },
									{ "mData": "user_name" },
									{ "mData": "phone_number" },
									{ "mData": "amount" },	
									{ "mData": "amount_paid" },	
									{ "mData": "payment_status" },						
									{ "mData": "order_status" },
									{ "mData": "Action" }
									] 
								});
							}else{
								$('.product_table').html('No Data is available...');	
							}					
						}
					});
				
				}
						
			}
		}
	});	
}
function changeFranchiseeOrder(regAuth,paymenttype){
	$('.product_table').html('Please wait loading....');
	var cid=$('#category').val();
	var scid=$('#subcategoryid').val();
	if(regAuth=='ordesonline'){
		if( cid!='' && scid==''){
			var query=BASE_PATH+'/users/order-view-ajax?cid='+cid+'&payment_mode='+paymenttype;
		}else if( cid!='' && scid!=''){
			var query=BASE_PATH+'/users/order-view-ajax?cid='+cid+'&scid='+scid+'&payment_mode='+paymenttype;
		}else if(cid=='' && scid==''){
			var query=BASE_PATH+'/users/order-view-ajax?payment_mode='+paymenttype;
		}
	}else{
		if( cid!='' && scid==''){
			var query=BASE_PATH+'/users/order-offline-view-ajax?cid='+cid+'&payment_mode='+paymenttype;
		}else if( cid!='' && scid!=''){
			var query=BASE_PATH+'/users/order-offline-view-ajax?cid='+cid+'&scid='+scid+'&payment_mode='+paymenttype;
		}else if(cid=='' && scid==''){
			var query=BASE_PATH+'/users/order-offline-view-ajax?payment_mode='+paymenttype;
		}
	}
	if(regAuth=='ordesonline'){
		$.ajax({
			type:'GET',
			dataType:'json',
			url:query,
			success: function(data){
			$('.product_table').html('<table  class="table table-bordered" cellpadding="0" cellspacing="0" width="100%" id="search_results"><thead><tr class="bg_header"><th>OrderId</th><th>Username</th><th>PhoneNumber</th><th>Amount</th><th>PaymentStatus</th><th>OrderStatus</th></tr></thead><tbody></tbody></table>');	
				if(data!='1'){
					eval(data);
					var oTable = $('#search_results').dataTable( {
						aoColumnDefs: [{bSortable: false,
										aTargets: [ 0 ]
										}],
						"bStateSave": true,
						"bAutoWidth": true,
						"sRowSelect": "multi",
						"sPaginationType": "full_numbers",
						"bProcessing": true,
						"aaData": data,
						"aoColumns": [
							{ "mData": "order_id" },
							{ "mData": "user_name" },
							{ "mData": "phone_number" },
							{ "mData": "amount" },	
							{ "mData": "payment_status" },						
							{ "mData": "order_status" }
						] 
					});
				}else{
					$('.product_table').html('No Data is available...');	
				}					
			}
		});
	}else{
		$.ajax({
			type:'GET',
			dataType:'json',
			url:query,
			success: function(data){
				$('.product_table').html('<table  class="table table-bordered" cellpadding="0" cellspacing="0" width="100%" id="search_results"><thead><tr class="bg_header"><th>OrderId</th><th>Username</th><th>PhoneNumber</th><th>Amount</th><th>DueAmount</th><th>PaymentStatus</th><th>OrderStatus</th><th>Action</th></tr></thead><tbody></tbody></table>');	
				if(data!='1'){
					eval(data);
					var oTable = $('#search_results').dataTable( {
						aoColumnDefs: [{bSortable: false,
										aTargets: [ 0 ]
										}],
						"bStateSave": true,
						"bAutoWidth": true,
						"sRowSelect": "multi",
						"sPaginationType": "full_numbers",
						"bProcessing": true,
						"aaData": data,
						"aoColumns": [
						{ "mData": "order_id" },
						{ "mData": "user_name" },
						{ "mData": "phone_number" },
						{ "mData": "amount" },	
						{ "mData": "amount_paid" },	
						{ "mData": "payment_status" },						
						{ "mData": "order_status" },
						{ "mData": "Action" }
						] 
					});
				}else{
					$('.product_table').html('No Data is available...');	
				}					
			}
		});
	}	
}
function updateFrencseeOrderStatus(){
	var paidAmount=$("#paidAmount").val();
	var dueAmount=$("#due_amount").val();
	var paidStatus=$("#paymentStatus").val();
	var hidorderid=$("#hid_order_id").val();
	if(paidAmount==''){
		alert(edit_orderPaidAmountEmptyMsg);return false;
	}else if(isNaN(paidAmount)){
		alert(edit_orderPaidAmountNumbersMsg);return false;
	}
	if(paidStatus==''){
		alert(edit_orderPaidStatusEmptyMsg);return false;
	}
	if(dueAmount<paidAmount){
		alert(edit_orderDueAmontCheckMsg);return false;
	}
	$("#edit_order").submit();
}
function getAdminDistrictAreas(page){
	
	if($("#districts").val()!="")
	{
		var dist=$("#districts").val();
	}else{
		var dist='';
	}
	if($("#area_id").val()!=''){
		var area_id=$("#add_url_area_id").val();
	}else{
		var area_id='';
	}
	var url=ADMIN_BASE_URL+'admin/get-admin-areas';
	var ses_area_id='';
	$.ajax({
		type:'POST',
		url:  url,
		data:{dist_id:dist,areas_id:area_id,ses_area_id:ses_area_id},
		success: function(data){
			$("#areas").html(data.list_areas);
		}
	});
}

function getAdminAreaBasedLocations(page){
	var ses_location_id='';
	var dist=$("#districts").val();
	if($("#areas").val()!=''){
		var area=$("#areas").val();
	}else if($("#add_url_area_id").val()!=""){
		var area=$("#add_url_area_id").val();
	}
	if($("#add_url_location_id").val()!=''){
		var loca_id=$("#add_url_location_id").val();
	}else{
		var loca_id='';
	}
	var url=ADMIN_BASE_URL+'admin/get-admin-locations';
	$.ajax({
		type:'POST',
		url:  url,
		data:{dist_id:dist,area_id:area,location_id:loca_id},
		success: function(data){
			$("#location").html(data.loca_list);
		}
	});
}
function subscribe(){
	var flag=true;  
	var email=$('#subscribe').val();
	if(email==""){
	   $("#errorEmail").html('required mail');
	   flag=false;   
	}else{
	    if(checkEmail(email)==0){
		  $("#errorEmail").html('email format not correct');
		  flag=false; 
	    }
	}
	$.ajax({
			type		:	'POST',
			url			:  	BASE_URL+'users/check-subscriber',
			data		:	{email:email},
			success: function(data){
				if(data.value==1){
					$('#errorEmail').html('Your already subscribed user');return false;
				}else{
					$.ajax({
								type		:	'POST',
								url			:  	BASE_URL+'users/subscriber',
								data		:	{email:email},
								success: function(data){
									if(data.value==1){
										$('#errorEmail').html('Your email successfully subscribed');
										$('#subscribe').val("");
									}
								}
						});	
				}
				
			}
	});
}
function multiLang(){
	var id = $("#language").val();
	if(id ==1)
		{
			$('#title_paper').on('keypress',function(event){convertThis(event);});
			$('#textAreaPaper').on('keypress',function(event){convertThis(event);});
			$('#titleMagazine').on('keypress',function(event){convertThis(event);});
			$('#textAreaMagazine').on('keypress',function(event){convertThis(event);});
			$('#titleHome').on('keypress',function(event){convertThis(event);});
			$('#textAreaHome').on('keypress',function(event){convertThis(event);});
		}
	else if(id ==2)
		{	
			$("#title_paper").off( "keypress" );				
			$("#textAreaPaper").off( "keypress" );				
			$("#titleMagazine").off( "keypress" );				
			$("#textAreaMagazine").off( "keypress" );				
			$("#textAreaHome").off( "keypress" );			
			$("#titleHome").off( "keypress" );			
		}	
	return false;
}		
